home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / firetrap.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  11KB  |  410 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *firetrap_bg1videoram,*firetrap_bg2videoram;
  15. unsigned char *firetrap_videoram,*firetrap_colorram;
  16. unsigned char *firetrap_scroll1x,*firetrap_scroll1y;
  17. unsigned char *firetrap_scroll2x,*firetrap_scroll2y;
  18. size_t firetrap_bgvideoram_size;
  19. size_t firetrap_videoram_size;
  20. static unsigned char *dirtybuffer2;
  21. static struct osd_bitmap *tmpbitmap2;
  22. static int flipscreen;
  23.  
  24.  
  25.  
  26. /***************************************************************************
  27.  
  28.   Convert the color PROMs into a more useable format.
  29.  
  30.   Fire Trap has one 256x8 and one 256x4 palette PROMs.
  31.   I don't know for sure how the palette PROMs are connected to the RGB
  32.   output, but it's probably the usual:
  33.  
  34.   bit 7 -- 220 ohm resistor  -- GREEN
  35.         -- 470 ohm resistor  -- GREEN
  36.         -- 1  kohm resistor  -- GREEN
  37.         -- 2.2kohm resistor  -- GREEN
  38.         -- 220 ohm resistor  -- RED
  39.         -- 470 ohm resistor  -- RED
  40.         -- 1  kohm resistor  -- RED
  41.   bit 0 -- 2.2kohm resistor  -- RED
  42.  
  43.   bit 3 -- 220 ohm resistor  -- BLUE
  44.         -- 470 ohm resistor  -- BLUE
  45.         -- 1  kohm resistor  -- BLUE
  46.   bit 0 -- 2.2kohm resistor  -- BLUE
  47.  
  48. ***************************************************************************/
  49. void firetrap_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  50. {
  51.     int i;
  52.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  53.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  54.  
  55.  
  56.     for (i = 0;i < 256;i++)
  57.     {
  58.         int bit0,bit1,bit2,bit3;
  59.  
  60.  
  61.         bit0 = (color_prom[0] >> 0) & 0x01;
  62.         bit1 = (color_prom[0] >> 1) & 0x01;
  63.         bit2 = (color_prom[0] >> 2) & 0x01;
  64.         bit3 = (color_prom[0] >> 3) & 0x01;
  65.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  66.         bit0 = (color_prom[0] >> 4) & 0x01;
  67.         bit1 = (color_prom[0] >> 5) & 0x01;
  68.         bit2 = (color_prom[0] >> 6) & 0x01;
  69.         bit3 = (color_prom[0] >> 7) & 0x01;
  70.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  71.         bit0 = (color_prom[256] >> 0) & 0x01;
  72.         bit1 = (color_prom[256] >> 1) & 0x01;
  73.         bit2 = (color_prom[256] >> 2) & 0x01;
  74.         bit3 = (color_prom[256] >> 3) & 0x01;
  75.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  76.  
  77.         color_prom++;
  78.     }
  79.  
  80.     /* reserve the last color for the transparent pen (none of the game colors can have */
  81.     /* these RGB components) */
  82.     *(palette++) = 1;
  83.     *(palette++) = 1;
  84.     *(palette++) = 1;
  85.  
  86.  
  87.     /* characters use colors 0-63 */
  88.     for (i = 0;i < TOTAL_COLORS(0);i++)
  89.         COLOR(0,i) = i;
  90.  
  91.     /* background #1 tiles use colors 128-191 */
  92.     for (i = 0;i < TOTAL_COLORS(1);i++)
  93.     {
  94.         if (i % Machine->gfx[1]->color_granularity == 0)
  95.             COLOR(1,i) = 256;    /* transparent */
  96.         else COLOR(1,i) = i + 128;
  97.     }
  98.  
  99.     /* background #2 tiles use colors 192-255 */
  100.     for (i = 0;i < TOTAL_COLORS(5);i++)
  101.         COLOR(5,i) = i + 192;
  102.  
  103.     /* sprites use colors 64-127 */
  104.     for (i = 0;i < TOTAL_COLORS(9);i++)
  105.         COLOR(9,i) = i + 64;
  106. }
  107.  
  108.  
  109.  
  110. /***************************************************************************
  111.  
  112.   Start the video hardware emulation.
  113.  
  114. ***************************************************************************/
  115. int firetrap_vh_start(void)
  116. {
  117.     if ((dirtybuffer = malloc(firetrap_bgvideoram_size)) == 0)
  118.     {
  119.         return 1;
  120.     }
  121.     memset(dirtybuffer,1,firetrap_bgvideoram_size);
  122.  
  123.     /* the background area is twice as wide and twice as tall as the screen */
  124.     if ((tmpbitmap = osd_create_bitmap(2*Machine->drv->screen_width,2*Machine->drv->screen_height)) == 0)
  125.     {
  126.         free(dirtybuffer);
  127.         return 1;
  128.     }
  129.  
  130.     if ((dirtybuffer2 = malloc(firetrap_bgvideoram_size)) == 0)
  131.     {
  132.         osd_free_bitmap(tmpbitmap);
  133.         free(dirtybuffer);
  134.         return 1;
  135.     }
  136.     memset(dirtybuffer2,1,firetrap_bgvideoram_size);
  137.  
  138.     /* the background area is twice as wide and twice as tall as the screen */
  139.     if ((tmpbitmap2 = osd_create_bitmap(2*Machine->drv->screen_width,2*Machine->drv->screen_height)) == 0)
  140.     {
  141.         osd_free_bitmap(tmpbitmap);
  142.         free(dirtybuffer2);
  143.         free(dirtybuffer);
  144.         generic_vh_stop();
  145.         return 1;
  146.     }
  147.  
  148.     return 0;
  149. }
  150.  
  151.  
  152.  
  153. /***************************************************************************
  154.  
  155.   Stop the video hardware emulation.
  156.  
  157. ***************************************************************************/
  158. void firetrap_vh_stop(void)
  159. {
  160.     osd_free_bitmap(tmpbitmap);
  161.     osd_free_bitmap(tmpbitmap2);
  162.     free(dirtybuffer);
  163.     free(dirtybuffer2);
  164. }
  165.  
  166.  
  167.  
  168. WRITE_HANDLER( firetrap_bg1videoram_w )
  169. {
  170.     if (firetrap_bg1videoram[offset] != data)
  171.     {
  172.         dirtybuffer[offset] = 1;
  173.  
  174.         firetrap_bg1videoram[offset] = data;
  175.     }
  176. }
  177.  
  178. WRITE_HANDLER( firetrap_bg2videoram_w )
  179. {
  180.     if (firetrap_bg2videoram[offset] != data)
  181.     {
  182.         dirtybuffer2[offset] = 1;
  183.  
  184.         firetrap_bg2videoram[offset] = data;
  185.     }
  186. }
  187.  
  188.  
  189.  
  190. WRITE_HANDLER( firetrap_flipscreen_w )
  191. {
  192.     if (flipscreen != (data & 1))
  193.     {
  194.         flipscreen = data & 1;
  195.         memset(dirtybuffer,1,firetrap_bgvideoram_size);
  196.         memset(dirtybuffer2,1,firetrap_bgvideoram_size);
  197.     }
  198. }
  199.  
  200.  
  201.  
  202. /***************************************************************************
  203.  
  204.   Draw the game screen in the given osd_bitmap.
  205.   Do NOT call osd_update_display() from this function, it will be called by
  206.   the main emulation engine.
  207.  
  208. ***************************************************************************/
  209. void firetrap_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  210. {
  211.     int offs;
  212.  
  213.  
  214.     /* for every character in the Video RAM, check if it has been modified */
  215.     /* since last time and update it accordingly. */
  216.     for (offs = firetrap_bgvideoram_size - 1;offs >= 0;offs--)
  217.     {
  218.         if ((offs & 0x100) == 0)
  219.         {
  220.             if (dirtybuffer[offs] || dirtybuffer[offs+0x100])
  221.             {
  222.                 int sx,sy,flipx,flipy;
  223.  
  224.  
  225.                 dirtybuffer[offs] = dirtybuffer[offs+0x100] = 0;
  226.  
  227.                 sx = (offs / 16) & 0x0f;
  228.                 sy = 31 - offs % 16;
  229.                 if (offs & 0x200) sy -= 16;
  230.                 if (offs & 0x400) sx += 16;
  231.                 flipx = firetrap_bg1videoram[offs+0x100] & 0x08;
  232.                 flipy = firetrap_bg1videoram[offs+0x100] & 0x04;
  233.                 if (flipscreen)
  234.                 {
  235.                     sx = 31 - sx;
  236.                     sy = 31 - sy;
  237.                     flipx = !flipx;
  238.                     flipy = !flipy;
  239.                 }
  240.  
  241.                 drawgfx(tmpbitmap,Machine->gfx[1 + (firetrap_bg1videoram[offs+0x100] & 0x03)],
  242.                         firetrap_bg1videoram[offs],
  243.                         (firetrap_bg1videoram[offs+0x100] & 0x30) >> 4,
  244.                         flipx,flipy,
  245.                         16*sx,16*sy,
  246.                         0,TRANSPARENCY_NONE,0);
  247.             }
  248.  
  249.             if (dirtybuffer2[offs] || dirtybuffer2[offs+0x100])
  250.             {
  251.                 int sx,sy,flipx,flipy;
  252.  
  253.  
  254.                 dirtybuffer2[offs] = dirtybuffer2[offs+0x100] = 0;
  255.  
  256.                 sx = (offs / 16) & 0x0f;
  257.                 sy = 31 - offs % 16;
  258.                 if (offs & 0x200) sy -= 16;
  259.                 if (offs & 0x400) sx += 16;
  260.                 flipx = firetrap_bg2videoram[offs+0x100] & 0x08;
  261.                 flipy = firetrap_bg2videoram[offs+0x100] & 0x04;
  262.                 if (flipscreen)
  263.                 {
  264.                     sx = 31 - sx;
  265.                     sy = 31 - sy;
  266.                     flipx = !flipx;
  267.                     flipy = !flipy;
  268.                 }
  269.  
  270.                 drawgfx(tmpbitmap2,Machine->gfx[5 + (firetrap_bg2videoram[offs+0x100] & 0x03)],
  271.                         firetrap_bg2videoram[offs],
  272.                         (firetrap_bg2videoram[offs+0x100] & 0x30) >> 4,
  273.                         flipx,flipy,
  274.                         16*sx,16*sy,
  275.                         0,TRANSPARENCY_NONE,0);
  276.             }
  277.         }
  278.     }
  279.  
  280.  
  281.     /* copy the background graphics */
  282.     {
  283.         int scrollx,scrolly;
  284.  
  285.  
  286.         if (flipscreen)
  287.         {
  288.             scrolly = -(firetrap_scroll2x[0] + 256 * firetrap_scroll2x[1]);
  289.             scrollx = 256 + (firetrap_scroll2y[0] + 256 * firetrap_scroll2y[1]);
  290.         }
  291.         else
  292.         {
  293.             scrolly = 256 + (firetrap_scroll2x[0] + 256 * firetrap_scroll2x[1]);
  294.             scrollx = -(firetrap_scroll2y[0] + 256 * firetrap_scroll2y[1]);
  295.         }
  296.         copyscrollbitmap(bitmap,tmpbitmap2,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  297.  
  298.         if (flipscreen)
  299.         {
  300.             scrolly = -(firetrap_scroll1x[0] + 256 * firetrap_scroll1x[1]);
  301.             scrollx = 256 + (firetrap_scroll1y[0] + 256 * firetrap_scroll1y[1]);
  302.         }
  303.         else
  304.         {
  305.             scrolly = 256 + (firetrap_scroll1x[0] + 256 * firetrap_scroll1x[1]);
  306.             scrollx = -(firetrap_scroll1y[0] + 256 * firetrap_scroll1y[1]);
  307.         }
  308.         copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_COLOR,256);
  309.     }
  310.  
  311.  
  312.     /* Draw the sprites. */
  313.     for (offs = 0;offs < spriteram_size; offs += 4)
  314.     {
  315. //        if (spriteram[offs] & 0x20)
  316.         {
  317.             int sx,sy,flipx,flipy,code,color;
  318.  
  319.  
  320.             /* the meaning of bit 3 of [offs] is unknown */
  321.  
  322.             sy = spriteram[offs];
  323.             sx = spriteram[offs + 2];
  324.             code = spriteram[offs + 3] + 4 * (spriteram[offs + 1] & 0xc0);
  325.             color = ((spriteram[offs + 1] & 0x08) >> 2) | (spriteram[offs + 1] & 0x01);
  326.             flipx = spriteram[offs + 1] & 0x04;
  327.             flipy = spriteram[offs + 1] & 0x02;
  328.             if (flipscreen)
  329.             {
  330.                 sx = 240 - sx;
  331.                 sy = 240 - sy;
  332.                 flipx = !flipx;
  333.                 flipy = !flipy;
  334.             }
  335.  
  336.             if (spriteram[offs + 1] & 0x10)    /* double width */
  337.             {
  338.                 if (flipscreen) sy -= 16;
  339.  
  340.                 drawgfx(bitmap,Machine->gfx[9],
  341.                         code & ~1,
  342.                         color,
  343.                         flipx,flipy,
  344.                         sx,flipy ? sy : sy + 16,
  345.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  346.                 drawgfx(bitmap,Machine->gfx[9],
  347.                         code | 1,
  348.                         color,
  349.                         flipx,flipy,
  350.                         sx,flipy ? sy + 16 : sy,
  351.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  352.  
  353.                 /* redraw with wraparound */
  354.                 drawgfx(bitmap,Machine->gfx[9],
  355.                         code & ~1,
  356.                         color,
  357.                         flipx,flipy,
  358.                         sx - 256,flipy ? sy : sy + 16,
  359.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  360.                 drawgfx(bitmap,Machine->gfx[9],
  361.                         code | 1,
  362.                         color,
  363.                         flipx,flipy,
  364.                         sx - 256,flipy ? sy + 16 : sy,
  365.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  366.             }
  367.             else
  368.             {
  369.                 drawgfx(bitmap,Machine->gfx[9],
  370.                         code,
  371.                         color,
  372.                         flipx,flipy,
  373.                         sx,sy,
  374.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  375.  
  376.                 /* redraw with wraparound */
  377.                 drawgfx(bitmap,Machine->gfx[9],
  378.                         code,
  379.                         color,
  380.                         flipx,flipy,
  381.                         sx - 256,sy,
  382.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  383.             }
  384.         }
  385.     }
  386.  
  387.  
  388.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  389.     for (offs = firetrap_videoram_size - 1;offs >= 0;offs--)
  390.     {
  391.         int sx,sy;
  392.  
  393.  
  394.         sx = offs / 32;
  395.         sy = 31 - offs % 32;
  396.         if (flipscreen)
  397.         {
  398.             sx = 31 - sx;
  399.             sy = 31 - sy;
  400.         }
  401.  
  402.         drawgfx(bitmap,Machine->gfx[0],
  403.                 firetrap_videoram[offs] + 256 * (firetrap_colorram[offs] & 0x01),
  404.                 (firetrap_colorram[offs] & 0xf0) >> 4,
  405.                 flipscreen,flipscreen,
  406.                 8*sx,8*sy,
  407.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  408.     }
  409. }
  410.